package com.jiangjiang.eshop.inventory.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.inventory.domain.GoodsStockEntity;
import com.jiangjiang.eshop.inventory.mapper.InventoryGoodsStockMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Jianghaowen
 * @Date 2021/6/7
 * @Description: TODO
 * @Version V1.0
 **/
@Service
public class InventoryGoodsStockService extends ServiceImpl<InventoryGoodsStockMapper, GoodsStockEntity> {

    /**
     * 根据商品id查询商品库存
     * @param goodsSkuId 商品sku id
     * @return
     */
    public GoodsStockEntity queryByGoodsSkuId(Long goodsSkuId){
        LambdaQueryWrapper<GoodsStockEntity> wrapper = Wrappers.<GoodsStockEntity>lambdaQuery().eq(GoodsStockEntity::getGoodsSkuId, goodsSkuId);
        return this.getOne(wrapper);
    }


    /**
     * 根据商品id集合查询商品库存
     * @param goodsSkuIds 商品sku id
     * @return
     */
    public List<GoodsStockEntity> queryByGoodsSkuIds(List<Long> goodsSkuIds){
        LambdaQueryWrapper<GoodsStockEntity> wrapper = Wrappers.<GoodsStockEntity>lambdaQuery().in(GoodsStockEntity::getGoodsSkuId, goodsSkuIds);
        return this.baseMapper.selectList(wrapper);
    }
}
